/*
	Mo.js
	javascript framework
	author:
			Wiki[MO]	gwikimo@gmail.com	
			Lay 			veryide@qq.com
			
	#UI 扩展，包括页面消息、对话框、星级评分等#
*/

if(typeof Mo != 'function'){
	var Mo = { plugin:[] }
}


/*
	评分组件
	
	box		容器名称
	min		最小评分
	max		最大评分
	def		默认评分
	grey		默认图片
	light		高亮图片
	func		回调函数
*/

Mo.Grade = function( box , min , max , def , grey , light , func ){

	//评分容器
	this.Box = box;
	
	//最小评分
	this.Min = min;
	
	//最大评分
	this.Max = max;
	
	//默认分数
	this.Def = def;

	//默认图片
	this.Grey = grey;

	//高亮图片
	this.Light = light;
	
	//回调函数
	this.Func = func;
	
	///////////////////
	
	var self = this;
	
	//初始化
	this.Inti = function(){
	
		//创建评分图片
		for( var i = this.Min; i <= this.Max ; i++ ){
			Mo( box ).create( "img" , { "rel" : i , "src" : this.Grey } );		
		}
		
		//绑定评分操作
		Mo( box + " img" ).bind( 'mouseover' , function( index , event ){
			
			//高亮当前
			self.Play( this.rel );

			//回调评分
			self.Return( this.rel );
			
		}).bind( 'mouseout' , function( index , event ){

			//高亮默认
			self.Play( self.Def );

			//回调评分
			self.Return( self.Def );

		}).bind( 'click' , function( index , event ){

			//保存默认
			self.Def = this.rel;
			
			//回调评分
			self.Return( this.rel );

		});
	
	}
	
	/*
		高亮部分
		rate	分值
	*/
	this.Play = function( rate ){

		Mo( box + " img" ).foreach( function( ele , index ){

			//高亮部分
			if( ele.rel <= rate  ){				
				this.src = self.Light;
			}else{
				this.src = self.Grey;
			}

		});
	
	}
	
	/*
		执行回调
		rate	分值
	*/
	this.Return = function( rate ){
	
		//回调评分
		if( typeof this.Func == 'function' ) this.Func( rate );
	
	}
	
	///////////////
	
	this.Inti();
	
	this.Play( this.Def );

}

/*
	创建对话框
	id		对象ID
	a		标题
	b		内容
	c		宽度
	d		高度
	e		配置
*/
Mo.Dialog = function(id,a,b,c,d,e){
	this.id		= id;
	this.title  = a;
	this.html   = b;
	this.width  = c;
	this.height = d;
	/*
	this.width  = c ? c : 400;
	this.height = d ? d : 400;
	*/
	this.mode	= '';
	this.config = e ? e : {};
	
	var self = this;
	
	//窗口关闭时回调
	this.onClose = function(){
		return true;
	}
	
	//窗口最小化时回调
	this.onMinimize = function(){
		return true;
	}
	
	//窗口最大化时回调
	this.onMaximize = function(){
		return true;
	}

	//窗口创建时回调
	this.onCreate = function(){
		
	}
	
	//居中窗口
	this.Center = function(){
		
		var doc = Mo.document;
		
		var div = Mo( "#"+this.id ).choice(0);
		
		//尺寸
		if( this.width ) div.style.width	= this.width+"px";
		if( this.height ) div.style.height= this.height+"px";	
		
		var pos = Mo( "#"+this.id ).position();
		
		//位置
		var top = doc.scrollTop+(doc.clientHeight/2)-(pos.height/2);
			top = top<0 ? 20 : top;

		var left =(doc.scrollWidth-pos.width)/2;
			left = left<0 ? 20 : left;

			div.style.left	= left+"px";
			div.style.top	= top+"px";		
			//div.style.zIndex= Mo.layer;
		
		//背景
		if( this.config["lock"] ){		
			var bg = Mo( "#"+this.id+"-bg" ).choice(0);
			bg.style.height = Math.max(doc.scrollHeight,doc.offsetHeight) +"px";
			bg.style.width  = "100%";
		}
		
	}
			
	//创建窗口
	this.Create	= function(){
		
		//已存在对象
		if( Mo( "#"+this.id ).verify() ){
			
			//显示
			Mo( "#"+this.id ).toggle();
			
			return true;
		}
	
		//灰背景
		if( this.config["lock"] ){
			
			var css="position:absolute; background:#666; filter:alpha(opacity=20); opacity:0.2; z-index:"+Mo.layer+"; top:0;left:0;";
		
			//bg
			var bg = document.createElement("DIV");
				bg.id = this.id+"-bg";
				bg.setAttribute("style",css);
				bg.style.cssText=css;
				
				document.body.appendChild(bg);
			
		}
		
		
		//创建新对象
		var div	= document.createElement("div");
			div.className	= this.config["class"] ? this.config["class"] : "package";
			div.id			= this.id;
		
		//dl
		var dl=document.createElement("dl");
		
		//dt
		var dt=document.createElement("dt");
		
			if( this.config["remove"] ){						
				var re = document.createElement("span");
					re.className = "remove";							
					dt.appendChild(re);
	
				//关闭动作
				re.onclick = this.Remove;
			}
						
			if( this.config["maximize"] ){
				var ma=document.createElement("span");
					ma.className = "maximize";							
					dt.appendChild(ma);
	
				//最大化动作
				ma.onclick = this.Maximize;
			}
						
			if( this.config["minimize"] ){
				var mi=document.createElement("span");
					mi.className = "minimize";							
					dt.appendChild(mi);
	
				//最小化动作
				mi.onclick = this.Minimize;
			}
			
			dt.appendChild(document.createTextNode(this.title));
				
			dl.appendChild(dt);
				
		//dd
		var dd=document.createElement("dd");
			dd.id=this.id+"-dd";
			dd.innerHTML = this.html;
			
			dl.appendChild(dd);
		
		div.appendChild(dl);
		
		document.body.appendChild(div);
		
		//居中显示
		this.Center();
		
		//回调事件
		self.onCreate( self );
	
		//未加载 Drag 组件
		//if(!Mo.script["drag"]) return false;
		
		//拖动样式		
		dt.className = "drag";

		//拖动支持
		var dg = new Mo.Drag(dt,div);
		
		dt.onclick = function(){
			//Mo.layer++;
			//div.style.zIndex=Mo.layer;	
		}
		
		//开始拖动
		dg.onDrag = function() {
			//Mo.layer++;
			//div.style.zIndex=Mo.layer;
		}
		
		//开始拖动
		dg.onStart = function() {
			this.style.filter="alpha(opacity=60)";
			this.style.opacity=0.6;
		}

		//结束拖动
		dg.onEnd = function(x, y){		
			this.style.filter="alpha(opacity=100)";
			this.style.opacity=1;				
		}

	}
	
	//关闭窗口
	this.Remove = function(){
		if( self.onClose() ){
			Mo( "#"+self.id ).remove();
			Mo( "#"+self.id+"-bg" ).remove();
		}
	}
	
	//最小化窗口
	this.Minimize = function(){
		if( self.onMinimize() ){
			Mo( "#"+self.id ).toggle();
		}
	}
	
	//最大化窗口
	this.Maximize = function(){
		if( self.onMaximize() ){	
			
			//主窗口
			var div	= $(self.id);
			
			if( self.mode == 'Maximize' ){
				
				div.style.height= "";
				
				//居中显示
				self.Center();
				
				//正常模式
				self.mode = '';
				
				//切换样式
				this.className = 'maximize';
					
			}else{
		
				var doc = Mo.document;
				
				div.style.width	= "100%";
				//div.style.height= doc.clientHeight-1+"px";
				div.style.height= "100%";
				div.style.left= "0px";
				div.style.top =  "-2px";
				
				//最大化模式
				self.mode = 'Maximize';
				
				//切换样式
				this.className = 'toggle';
					
			}
			
		}
	}
	
	//this.Create();
}

/*
	倒计时
	path	选择器
	value	对比值
	callback	回调函数
*/
Mo.Selector = function(path,value,callback){
	
	var box = $E(path);	
	
	if( typeof callback != 'function'){
		
		var callback =function(value,rel,box){
			if( value == rel ){
				box.className='active';
			}else{
				box.className='';
			}
		};
		
	}
	
	for(var i=0; i<box.length; i++){		
		callback(value,box[i].getAttribute("rel"),box[i]);
	}	

}

/*
	面板组件控制器
*/
Mo.Planer = function(box){
	
	var box = box;
	
	//表格对象
	this.getTable = function(obj){
		var tab = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
		return tab;
	}
	
	//删除组件
	this.remove = function(obj){
		if( this.getNodes(box) == 1 ){
			alert('只剩下一个啦！');
			return;
		}								
			
		if( getConfirm('确定要删除掉这个吗？') ){
			var tab = this.getTable(obj);								
			remove(tab);
		}
	}
	
	/*
		新建组件
		func	回调函数
		
		//color
	*/
	this.copy = function(func){
		
		var tag = this.getFirst(box).cloneNode(true);
		
		try{
			
			tag.getElementsByTagName("input")[0].value = "";
			tag.getElementsByTagName("textarea")[0].value = "";
			
		}catch(e){
			
		}
		
		//if(color) tag.style.background = getColor();
		
		box.appendChild(tag);		
		tag.scrollIntoView(true);
		
		if( typeof func == 'function'){
			func(tag);
		}
	}
	
	this.move = function(obj,dest){
		
		var tab = this.getTable(obj);
				
		//非固定
		if( tab.getAttribute("fixed") ) return;				
		
		if( dest == "down" ){
			if( tab.nextSibling == null ){
				return false;
			}else{
				
				//非固定
				if( this.getNext(tab).getAttribute("fixed") ) return;
				
				//交换节点
				tab.swapNode(this.getNext(tab));
			}
		}
		
		if( dest == "up" ){
			if( tab.previousSibling==null ){
				return false;
			}else{
				
				//非固定
				if( this.getPrev(tab).getAttribute("fixed") ) return;
				
				//交换节点
				tab.swapNode(this.getPrev(tab));
			}
		}						
		
	}
	
	//第一个节点
	this.getNodes = function(n){
		var x = n.childNodes;
		
		var z=0;
		for (var i=0;i<x.length;i++){
			if (x[i].nodeType==1){
				z++;
			}
		}
		
		return z;
	}
	
	//第一个节点
	this.getFirst = function(n){
		var x = n.firstChild;
		while (x.nodeType!=1){
			x = x.nextSibling;
		}
		return x;
	}

	
	//下一个节点
	this.getNext = function(n){
		var x = n.nextSibling;
		while (x.nodeType!=1){
			x = x.nextSibling;
		}
		return x;
	}
	
	//上一个节点
	this.getPrev = function(n){
		var x = n.previousSibling;
		while (x.nodeType!=1){
			x = x.previousSibling;
		}
		return x;
	}
		
}


/*
	倒计时
	expire		过期时间,Unix 时间戳（秒）
	func		回调函数
*/
Mo.DateDiff = function( expire, func ){

	//空函数
	if( typeof func != 'function' ) var func = function(){};
		
	//过期时间
	if( !expire ){
		return false;
	}
	
	//转换成微秒
	var expire = Math.round(parseInt(expire)*1000);	
		
	//已过期
	if( new Date().getTime() >= expire ){
		//回调	
		func( -1, { "d":0, "h":0, "m":0, "s":0 } );
	}else{
	
		var asd = expire;
		window.setInterval(function(){
		
			//已过期
			if( new Date().getTime() > expire ){
				//回调
				func( -1, { "d":0, "h":0, "m":0, "s":0 } );
			}else{
				var DifferenceHour = -1;
				var DifferenceMinute = -1;
				var DifferenceSecond = -1;
				var daysms = 24 * 60 * 60 * 1000;
				var hoursms = 60 * 60 * 1000;
				var Secondms = 60 * 1000;
				var microsecond = 1000;
				var time = new Date();
				var convertHour = DifferenceHour;
				var convertMinute = DifferenceMinute;
				var convertSecond = DifferenceSecond;
				var Result = Diffms = asd - time.getTime();
				DifferenceHour = Math.floor(Diffms / daysms);
				Diffms -= DifferenceHour * daysms;
				DifferenceMinute = Math.floor(Diffms / hoursms);
				Diffms -= DifferenceMinute * hoursms;
				DifferenceSecond = Math.floor(Diffms / Secondms);
				Diffms -= DifferenceSecond * Secondms;
				var dSecs = Math.floor(Diffms / microsecond);
				
				if(convertHour != DifferenceHour){
					var a = DifferenceHour;
				}
				
				if(convertMinute != DifferenceMinute){
					var b = DifferenceMinute;
				}
				
				if(convertSecond != DifferenceSecond){
					var c = DifferenceSecond;
					var d = dSecs;
				}
				
				//var dd = "clock("+asd+",'"+id+"')";
				//clk.innerHTML=a+"天"+b+"小时"+c+"分钟"+d+"秒";
				
				/*
					回调函数
					Result	相差秒数
					date	[json]
							a	天
							b	小时
							c	分钟
							d	秒
				*/				
				func( parseInt( Result / 1000 ) , { "d":a, "h":b, "m":c, "s":d } );
			}
			
		},1000);
	}
}

/*
	进度条
*/
Mo.Process = function(){
	
	this.groups=[];
	
	var self = this;

	/*
	参数：
	gid 唯一组ID
	*/
	this.Group = function(gid){
		self.groups[gid] = {"GID":gid, "COUNT":0, "OPTIONS":[]};
		this.gid = gid;
		
		/*
		参数：
		oid 唯选项ID
		val 值
		*/
		this.Option = function(oid,val){
			if( val<0 ) val = 0;			
			self.groups[this.gid]["COUNT"] += val;			
			if( oid !== null ) self.groups[this.gid]["OPTIONS"][oid] = {"OID":oid, "COUNT":val};
		}
		
	}
	
	this.Show = function(){
		for(var x in self.groups){
			
			for(var n in self.groups[x]["OPTIONS"]){
				var p = Math.round( self.groups[x]["OPTIONS"][n]["COUNT"] / self.groups[x]["COUNT"] *100);
				
				(function(){
					var N = n;
					var P = p;
					var i = 0;
					
					var func = function(){
						if( i<=P ){
							$('option-'+N).style.width = i +'%';
							$('percent-'+N).innerHTML = i +'%';
							i++;
						}else{
							clearInterval(inti);	
						}
					};
					
					var inti = window.setInterval(func, 2);
				
				})();
			}
			
		}
	}
}

/*
	筛选表格
	
	参数：
		table		表格对象或ID
		fun			匿名修理函数
	
	返回：
		tr			行对象
		event		event对象
*/
Mo.Table = function(table,funs){
	
	if(typeof table == 'string') table = $(table);
	var tr = table.getElementsByTagName("tr");
	
	for(var i=0;i<tr.length;i++){
		
		var self = tr[i];
		
		for(var n=0;n<funs.length;n+=2){
			(function(){
				var evt = funs[n];
				var fun = funs[n+1];
				self['on'+evt] = function(e){
					var e = e || event;
					fun(this,e);
				}
			})();
		}
		
	}
}

/*
	操作消息
	用于页面操作反馈
	
	参数：
		id			信息框ID
		class		附加的样式名称
		html		信息框内容
		time		显示时间,秒
		func		回调函数
*/
Mo.Message = function( style, html, time, func ){

	//空函数
	if( typeof func != 'function' ) var func = function(){};

	///////////////////////

	//分配ID
	var id = "_msg_"+ Mo.random(10) +"_";

	//对象已存，直接显示
	Mo( "#"+id ).remove();

	//创建对象
	Mo( document.body ).create( "div" , { "id" : id, "className" : style, "innerHTML" : html } );
	
	var doc = Mo.document;

	//对象位置
	var pos = Mo( "#"+id ).position();
	
	Mo( "#"+id ).style( { 
		"left" : (doc.scrollWidth-pos.width)/2 + "px", 
		"top" : doc.scrollTop + (doc.clientHeight/2) - (pos.height/2) + "px"
	});
	
	window.setTimeout(function(){
	
		//隐藏对象
		Mo( "#"+id ).hide();
		
		//回调函数
		func( Mo( "#"+id ).choice(0) );
		
	},1000*time);
	
}

/*
	小纸条/小提示
	用于页面任何位置
	替代	Mo.ShowSelect
	
	参数：
		self	定位参照对象
		event	事件对象
		style	样式名称
		html	写入内容		
		action	关闭纸条的事件名称[ 'mouseout'|'click' 等等 ]
		fX	修正X位置
		fY	修正Y位置
*/
		
Mo.Tips = function( self, event, style, html, action, fX, fY ){

	//停止冒泡
	Mo.Event( event ).stop();

	///////////////////////

	//分配ID
	var id = "_tips_"+ Mo.random(10) +"_";

	//对象已存，直接显示
	Mo( "#"+id ).remove();

	//创建对象
	Mo( document.body ).create( "div" , { "id" : id, "className" : style } );

	//对象位置
	var pos = Mo( self ).position();

	//修正位置
	fX = fX ? fX : 0 ;
	fY = fY ? fY : 0 ;

	///////////////////////

	//设置样式
	Mo( "#"+id ).style( {

		"position" 	: "absolute",
		"left"	 	: pos.left + fX +"px",
		"top" 		: pos.top + fY   +"px",		
		"zIndex"	: "99999"

	}).bind( 'click' , function( index , event ){

		//停止冒泡
		Mo.Event( event ).stop();

	}).html( html );
	
	////////////////////////	

	//空白处点击时隐藏
	Mo( document ).bind( action ? action : 'mouseover' , function( index , event ){

		var ele = Mo.Event( event ).element();

		if( self != ele ){

			//回调函数
			Mo( "#"+id ).hide();

		}

	});
	
}

/*
	淡入淡出幻灯片
	原作者：王晓斌 (http://www.13100.net/?action=show&id=40)
	
	方法：
		Add(o)					添加HTML对象
		Play(n)					开始播放幻灯片 [n 默认页索引,不能为空]
		onChange(n)			回调函数,返回当前页索引
		
	属性：
		Speed					图片淡入淡出的速度(默认10)[毫秒]
		Timer						图片切换的时间(默认2000)[毫秒]
*/
Mo.FadeBox = function() {
    this.Speed = 10;
    this.Timer = 2000;
    this.Alpha = 100;
    this.iCounter = 0;
    this.iCurrent = 0;
    this.iClock = null;
    this.Images = new Array();
	
	//添加
    this.Add = function(o) {
        this.Images[this.iCounter]=o;
        this.iCounter++;
    }
	
	var self = this;
	
	//播放时调用
	this.onChange= function(){
		
	}
	
	//淡入
    this.FadeIn = function() {
		var obj=this.Images[this.iCurrent];
		var style= "filter:alpha(opacity="+ parseInt(this.Alpha++) +");-moz-opacity:"+ (this.Alpha++/100) +";opacity:"+ (this.Alpha++/100) +";";
        
		obj.style.cssText=style;
		obj.setAttribute("style",style);		
		
        if (this.Alpha >= 100) {
            window.clearInterval(this.iClock);
            this.iClock = null;
            this.Play();
            this.onChange(this.iCurrent);
        }
    }
	
	//淡出
    this.FadeOut = function() {
		var obj=this.Images[this.iCurrent];
		var style= "filter:alpha(opacity="+ parseInt(this.Alpha--) +");-moz-opacity:"+ (this.Alpha--/100) +";opacity:"+ (this.Alpha--/100) +";";
        
		obj.style.cssText=style;
		obj.setAttribute("style",style);		
	
        if (this.Alpha <= -10){
            window.clearInterval(this.iClock);
            this.iClock = null;
			
			//隐藏当前
			this.Images[this.iCurrent].style.display="none";
			
			//显示下一页
			if(this.iCurrent+1==this.Images.length){
				this.iCurrent=0;
			}else{
				this.iCurrent++;
			}
			
			//初始下一页
			var obj=this.Images[this.iCurrent];
			var style= "filter:alpha(opacity=1);-moz-opacity:0.01;opacity:0.01;display:;";
			obj.style.cssText=style;
			obj.setAttribute("style",style);		

			this.iClock = setInterval(function(){self.FadeIn();},this.Speed);
        }
    }
	
	//下一个
    this.PlayNext = function() {
        this.iClock = setInterval(function(){self.FadeOut();},this.Speed);
    }
	
	//播放
    this.Play = function(n) {
		if(typeof(n)=="number"){
			//初始化
			for(var i=0;i<this.iCounter;i++){
				this.Images[i].style.display="none";
			}
			
			this.iCurrent=n;
			
			//默认页
			this.Images[n].style.display="";
		}

		setTimeout(function(){self.PlayNext();},this.Timer);
    }
}


/*
	选项卡/滑动门
	
	方法：
		Add(o,t)					添加卡片 [o 选项对象] [t 卡片对象]
		TabClass(a,d)			选项样式 [a 响应时样式] [d 未响应样式]
		BoxClass(a,d)			容器样式 [a 响应时样式] [d 未响应样式]
		Play(t)					播放第几张卡片 [t 卡片索引,从0开始]
		Auto(s)					自动播放选项卡 [s 毫秒后自动播放下一张卡片]
		onChange(n)			回调函数,返回当前页索引
		
	参数：
		e							侦听事件 [click | mouseover]
*/
Mo.TabMenu = function(e){
	this.Event = e;
	this.Cur=-1;
	this.Inter=null;
	this.Speed=0;
	
	this.Array = new Array();
	this.TClass = ["",""];
	this.BClass = ["",""];
	
	//选项卡样式
	this.TabClass = function(a,d){
		 this.TClass=[a,d];
	}

	//内容卡样式
	this.BoxClass = function(a,d){
		 this.BClass=[a,d];
	}

	//添加新选项卡
	this.Add = function(o,t){
		if(o && t){
			this.Array[this.Array.length]=[o,t];
		}
	}
	
	//选项卡改动时调用
	this.onChange = function(){
		
	}

	//选项卡改动
	this.Change = function(tab){
		for(var n=0; n< this.Array.length ;n++){
		
            if(this.TClass[0] || this.TClass[1]){
                this.Array[n][0].className=this.TClass[1];
			}
			
			//附加Class
			if(this.BClass[0] || this.BClass[1]){
				this.Array[n][1].className=this.BClass[1];
			}else{
				this.Array[n][1].style.display="none";
			}
			
		}
		
		var obj=this.Array[tab][0];
		if(this.TClass[0] || this.TClass[1]){
            obj.className=this.TClass[0];
		}
		
		var box=this.Array[tab][1];
		
		//附加Class
		if(this.BClass[0] || this.BClass[1]){
			box.className=this.BClass[0];
		}else{
			box.style.display="";
		}
		
		//暂停播放
		if(this.Inter){
			var self=this;
			box.onmouseover=function(){
				clearInterval(self.Inter);
			}
			box.onmouseout=function(){
				self.Auto(self.Speed);
			}
		}
		
		this.Cur=tab;
		this.onChange(tab);
	}

	//播放选项卡
	this.Play=function(t){
		var self=this;
		
		for(var n=0; n< this.Array.length ;n++){		
			var obj=this.Array[n][0];			
			(function(){    
				var tab=n;
				obj["on"+self.Event]=function(){
					self.Change(tab);
					clearInterval(self.Inter);
				}
				obj["onmouseout"]=function(){
					self.Auto(self.Speed);
				}
			})();

		}
		
		if(t<=this.Array.length-1){
			this.Change(t);
		}else{
			this.Change(0);
		}
	}
	
	//自动播放
	this.Auto=function(s){
		if(s){
			this.Speed=s;
			var self=this;
			
			this.Inter=window.setInterval(function(){
				if((self.Cur+1)<=self.Array.length-1){
					self.Cur++;
					self.Change(self.Cur);
				}else{
					self.Change(0);
				}
			},s);
		}
	}
}

/*
	显示窗口/iframe
		
	参数：
		id					容器ID
		title				标题名称
		url					页面URL地址
		width				页面宽,可用%
		height				页面高,可用%
		options				选项,JSON数据
*/
Mo.Window = function(id,title,url,width,height,options){
	
	if(typeof options!="object") var options={};
	
	var doc=Mo.getDocument();
	
	var tid=id+"-title";
	var obj=$(id);
	
	//灰背景
	if( options.lock ){
		var bid=id+"-bg";
		var css="position:absolute;background:#666;filter:alpha(opacity=20); opacity:0.2;z-index:"+Mo.layer+"; top:0;left:0;";
		var bg=$(bid);
	}
	
	if(!obj){
		
		if(options.lock){
			//bg
			bg=document.createElement("DIV");
			bg.id=bid;
			bg.setAttribute("style",css);
			bg.style.cssText=css;
			document.body.appendChild(bg);
			
			bg.style.height=doc.scrollHeight+"px";
			bg.style.width="100%";
		}

		//box
		obj=document.createElement("DIV");
		obj.id=id;
		document.body.appendChild(obj);
		
	}else{
		obj.style.display="";
	}
		
	if(width.toString().indexOf("%")>-1)	width=doc.scrollWidth*(parseInt(width)/100);
	if(height.toString().indexOf("%")>-1) 	height=doc.scrollHeight*(parseInt(height)/100);
	
	if(width>doc.scrollWidth){
		width=doc.scrollWidth-100;
		height+=30;
	}
	
	if(height>doc.scrollHeight){
		height=doc.scrollHeight-100;
		width+=30;
	}
	
	var str='<div id="'+tid+'" class="title" ondblclick="remove(\''+id+'\');remove(\''+bid+'\');" title="双击关闭"><span class="close" onclick="remove(\''+id+'\');remove(\''+bid+'\');" alt="关闭"><em>关闭</em></span><strong class="text">'+title+'</strong></div>';
	
	str+='<div class="box"><iframe id="'+id+'-iframe" name="'+id+'-iframe" width="100%" height="'+(height-30)+'" frameborder="0" src="' + url + '" /></div>';
		
	obj.innerHTML = str;
	
	
	var top=doc.scrollTop+(doc.clientHeight/2)-(height/2);
	if(top<0){
		top=20;		
	}
	
	var left=(doc.clientWidth-width)/2;
	if(left<0){
		left=20;
	}
	
	obj.style.left=left+"px";
	obj.style.top=top+"px";
	obj.style.width=width+"px";
	obj.style.height=height+"px";
	obj.style.zIndex=Mo.layer;
	
	//绑定ESC到关闭
	addKeyEvent(27,function(){
		remove(id);
		remove(bid);
	});
			
	addObjectEvent(document,"keyup",function(event){
		addKeyEvent.Listener(event);
	});	
	
	//未加载 Drag 组件
	if(!Mo.script["drag"]) return false;

	//拖动支持
	var drag=$(tid);
	Drag.init(drag, obj);
	//,null,10,doc.clientWidth-div.offsetWidth-10,10,doc.scrollTop + doc.clientHeight - div.offsetHeight-10
	/*
	drag.onmouseover=function(){
		this.style.cursor="move";
	}
	drag.onmouseout=function(){
		this.style.cursor="default";
	}
	
	drag.root.onStart = function() {
		Mo.layer++;
		obj.style.zIndex=Mo.layer;
	}
	*/
}

/*
	显示错误/alert
		
	参数：
		id					容器ID
		title				标题名称
		html				HTML代码
		options				选项,JSON数据
*/
Mo.Alert = function(id,title,html,options){
	
	if(typeof options!="object") var options={button:true};
	
	var tid=id+"-title";
	var bid=id+"-bg";
	
	var css="z-index:"+Mo.layer+";position:absolute;";
	
	var obj=$(id);
	var bg=$(bid);
	
	if(!obj){
		
		//bg
		bg=document.createElement("DIV");
		bg.id=bid;
		bg.className="background";
		bg.setAttribute("style",css);
		bg.style.cssText=css;
		bg.innerHTML='<iframe style="position:absolute; z-index:-1;width:100%;height:100%; filter:alpha(opacity=0);opacity:0;" frameborder="0" src="about:blank"></iframe>';
		document.body.appendChild(bg);

		//box
		obj=document.createElement("DIV");
		obj.id=id;
		document.body.appendChild(obj);

	}else{
		obj.style.display="";
	}
  
	var doc=Mo.getDocument();
	bg.style.height=doc.scrollHeight+"px";
	bg.style.width="100%";
  
	//这里使用双引号(在 Mo.Alert(\''+id+'\') 处)会导致语法错误
	var html='<div id="'+tid+'" class="title">'+title+'</div><div class="box">' + html + '</div>';
  
	if(options.button){
		html+='<div class="bar"><button type="button" id="'+id+'-button" onclick="remove(\''+bid+'\');remove(\''+id+'\');">关  闭</button></div>';
	}

	obj.innerHTML= html;
	
	obj.style.left	=	(doc.scrollWidth-obj.offsetWidth)/2+"px";
	obj.style.top	=	doc.scrollTop+(doc.clientHeight/2)-(obj.offsetHeight/2)+"px";
	obj.style.zIndex=	Mo.layer+1;

	//focus
	if(options.button){
		$(id+'-button').focus();
	}
	
	//未加载 Drag 组件
	if(!Mo.script["drag"]) return false;

	var drag=$(tid);
	Drag.init(drag, obj);
	drag.onmouseover=function(){
		this.style.cursor="move";
	}
	
	drag.onmouseout=function(){
		this.style.cursor="default";
	}
	
	drag.root.onStart = function(x, y) {
		Mo.layer++;
		obj.style.zIndex=Mo.layer;
		obj.style.filter="alpha(opacity=60)";
		obj.style.opacity=0.6;
	}
	
	drag.root.onEnd = function(x, y) {
		obj.style.filter="alpha(opacity=100)";
		obj.style.opacity=1;
	}
}


/*
	数字选择器
	object	Input对象
	value	JSON数据
	title	标题
	min		起始值
	max		结束值
	line	每行数量
*/
Mo.Soler = function( self, event, value, style, data, func, fX, fY ){

	//空函数
	if( typeof func != 'function' ) var func = function(){};

	//停止冒泡
	Mo.Event( event ).stop();
		
	///////////////////////

	//分配ID
	var id = "_timer_";

	//对象已存，直接显示
	Mo( "#"+id ).remove();

	//创建对象
	Mo( document.body ).create( "dl" , { "id" : id, "className" : style } );

	//对象位置
	var pos = Mo( self ).position();

	//修正位置
	fX = fX ? fX : 0 ;
	fY = fY ? fY : 0 ;
	
	///////////////////////

	//设置样式
	Mo( "#"+id ).style( {

		"position" 	: "absolute",
		"left"	 	: pos.left + fX +"px",
		"top" 		: pos.top + fY  +"px",		
		"zIndex"	: "99999"

	}).bind( 'click' , function( index , event ){

		//停止冒泡
		Mo.Event( event ).stop();

	});
		
	var tim = Mo.String( value ).trim().output();

	//颜色值，来自自定义属性
	var selected = Mo( self ).attr( "_value_" );
		
	for( var key in data ){
	
		var dt = Mo.create( "dt" , { "innerHTML" : key } );
		
		var dd = Mo.create( "dd" );
		
		var ul = Mo.create( "ul" );

		for(var i in data[key]){
		
			(function(){
	
				//颜色值，转成大写
				var value = data[key][i];
					
				var li = Mo.create( "li", { "innerHTML" : value, "className" : ( selected == value ? "active" : "" ) } );				

				Mo( li ).bind( 'click' , function( index , event ){
	
					/*
						回调函数
						color	颜色值
						self	当前对象
					*/
					func.call( self, value, self );
	
					//停止冒泡
					Mo.Event( event ).stop();
	
					//隐藏对象
					Mo( "#"+id ).hide();
	
					//保存颜色到自定义属性
					Mo( self ).attr( { "_value_" : value } );
	
				});
	
				Mo( ul ).append( li );
			
			})();

		}
		
		Mo( dd ).append( ul );
		
		Mo( "#"+id ).append( dt, dd );
	
	}

	//空白处点击时隐藏
	Mo( document ).bind( 'click' , function( index , event ){

		var ele = Mo.Event( event ).element();

		if( self != ele ){

			//回调函数
			Mo( "#"+id ).hide();

		}

	});
	
}


/*state*/
Mo.plugin.push("effect");